package cn.qyd.javathread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 邱运铎
 * @date 2024-03-14 21:14
 */
public class YuanZiXingAtomClassDemo {
    public AtomicInteger inc = new AtomicInteger(0);

    private void incrementMethod() {
        inc.getAndIncrement();
    }

    public static void main(String[] args) {
        YuanZiXingAtomClassDemo demo = new YuanZiXingAtomClassDemo();

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    demo.incrementMethod();
                }
            }).start();
        }

        while (Thread.activeCount() > 2)
            Thread.yield();

        System.out.println("add lock inc output " + demo.inc);
    }
}
